#include "adddocumentdlg.h"
#include "ui_adddocumentdlg.h"

AddDocumentDlg::AddDocumentDlg(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AddDocumentDlg)
{
    ui->setupUi(this);
}

AddDocumentDlg::~AddDocumentDlg()
{
    delete ui;
}

void AddDocumentDlg::on_bOK_clicked()
{
    QString title (ui->editTitle->text());
    QString content (ui->editContent->toPlainText());

    emit ok_clicked(title,content);
}

void AddDocumentDlg::on_bCancel_clicked()
{
    emit cancel_clicked();
}

void AddDocumentDlg::showDlg(AddDocumentDlg *addDocumentDlg)
{
    QDialog* dlg = new QDialog(nullptr);

    dlg->setWindowTitle(tr("Add Document"));

    QVBoxLayout *l = new QVBoxLayout(dlg);

    l->addWidget(addDocumentDlg);

    QObject::connect(addDocumentDlg,&AddDocumentDlg::cancel_clicked,[=](void){
        dlg->done(-1);
        delete dlg;
    });

    QObject::connect(addDocumentDlg,&AddDocumentDlg::ok_clicked,[=](const QString& title,const QString& content){
        qDebug()<<"title:"<<title<<'\n';
        qDebug()<<"content:"<<content<<'\n';
        dlg->done(0);
        delete dlg;
    });

    dlg->exec();
}

